#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

//通过系统调用将test.txt拷贝到test2.txt中
int main()
{
	int fd;
    int fd2;
	char buf[1024];
	fd = open("test.txt", O_RDONLY);
    if(fd==-1)
    {
        printf("open file failed\n");
        return -1;
    }
    fd2 = open("test2.txt", O_WRONLY);
    if(fd2==-1){
        printf("open file failed\n");
        return -1;
    }
	int recv_size=read(fd, buf, 1024);
    if(recv_size==-1){
        perror("read");
        close(fd);
        close(fd2);
        return -1;
    }
    write(fd2,buf,recv_size);
    exit(EXIT_SUCCESS);
	return 0;
}